package main

import (
	"encoding/json"
	"log"
	"rabbit/config"
	"rabbit/consts"
	"rabbit/inits"
	"rabbit/internal/dao"
	"rabbit/internal/model"
	"rabbit/internal/queue"
)

func main() {
	config.GetViperData()
	inits.InitMysql()
	inits.InitRabbitMq()

	msgs := queue.QueueSub(consts.CHAT_QUEUE)

	forever := make(chan bool)
	//启用协程处理消息
	go func() {
		for d := range msgs {
			//消息逻辑处理，可以自行设计逻辑
			log.Printf("Received a message: %s", d.Body)
			var data model.ChatHistory
			json.Unmarshal(d.Body, &data)
			dao.Create(&data)

		}
	}()

	log.Printf(" [*] Waiting for messages. To exit press CTRL+C")
	<-forever
}
